<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>observer模式 &mdash; programming v0.1 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '0.1',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/translations.js"></script>
    <link rel="author" title="关于这些文档" href="../about.html" />
    <link rel="top" title="programming v0.1 documentation" href="../index.html" />
    <link rel="up" title="设计模式学习笔记" href="index.html" />
    <link rel="next" title="decorator模式" href="decorator.html" />
    <link rel="prev" title="strategy模式" href="strategy.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="decorator.html" title="decorator模式"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="strategy.html" title="strategy模式"
             accesskey="P">上一页</a> |</li>
        <li><a href="../index.html">programming v0.1 documentation</a> &raquo;</li>
          <li><a href="index.html" accesskey="U">设计模式学习笔记</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="observer">
<h1>observer模式<a class="headerlink" href="#observer" title="永久链接至标题">¶</a></h1>
<div class="section" id="id1">
<span id="index-8"></span><span id="id2"></span><h2>observer模式定义<a class="headerlink" href="#id1" title="永久链接至标题">¶</a></h2>
<p><strong>observer</strong> 在对象之间定义了一个 <strong>一对多</strong> 的关系,所以
当一个对象状态变化时,其它的所有依赖对象会得到通知,并且
自动更新.</p>
</div>
<div class="section" id="id3">
<h2>问题描述<a class="headerlink" href="#id3" title="永久链接至标题">¶</a></h2>
<p>一个天气预报的服务商请你开发不同呈现形式的天气服务,可能包括:</p>
<ul class="simple">
<li>当前的天气状态</li>
<li>天气预报</li>
<li>其它</li>
</ul>
<p>参见下图:</p>
<img alt="../_images/weather.png" src="../_images/weather.png" />
<p>最初我们可能会按照如下的思路进行:</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">class</span> <span class="nc">WeatherData</span>
<span class="p">{</span>
    <span class="kt">void</span> <span class="n">measurementsChanged</span><span class="p">()</span>
    <span class="p">{</span>
        <span class="kt">float</span> <span class="n">temp</span> <span class="o">=</span> <span class="n">getTemperature</span><span class="p">();</span>
        <span class="kt">float</span> <span class="n">humi</span> <span class="o">=</span> <span class="n">getHumidity</span><span class="p">();</span>
        <span class="kt">float</span> <span class="n">pres</span> <span class="o">=</span>  <span class="n">getPression</span><span class="p">();</span>

        <span class="n">currentConditionDisplay</span><span class="p">.</span><span class="n">update</span><span class="p">(</span><span class="n">temp</span><span class="p">,</span> <span class="n">humi</span><span class="p">,</span> <span class="n">pres</span><span class="p">);</span>   <span class="c">//更新当前的显示</span>
        <span class="n">forcastDisplay</span><span class="p">.</span><span class="n">update</span><span class="p">(</span><span class="n">temp</span><span class="p">,</span> <span class="n">humi</span><span class="p">,</span> <span class="n">pres</span><span class="p">);</span>    <span class="c">//更新天气预报</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>但是存在的问题是明显的:</p>
<ul class="simple">
<li>显然不同的显示属于所谓 <strong>变化</strong> 的部分, 所以我们应该将其封装</li>
<li>当增加新的显示方式时, 需要更改 <strong>WeatherData</strong> 的代码,这是我们不希望的</li>
<li>其它</li>
</ul>
<p>因此我们使用 <strong>observer</strong> 模式来完成,使得 <strong>subject</strong> 和 <strong>observer</strong> 松耦合.</p>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last"><strong>subject</strong> 即被依赖者,亦即 <strong>被观察者</strong>, 它的变化会影响 <strong>观察者</strong> 的状态
<strong>observer</strong> 即依赖者,亦即 <strong>观察者</strong>, 它的会依赖于 <strong>subject</strong> 的变化</p>
</div>
<p>具体的 <strong>observer</strong> 类图如下:</p>
<img alt="../_images/observer.png" src="../_images/observer.png" />
</div>
<div class="section" id="id4">
<h2>具体的代码<a class="headerlink" href="#id4" title="永久链接至标题">¶</a></h2>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p>需要注意的是下面的实现采用的是 <strong>push</strong> 的方法,即 <em>subject</em> 将所有的信息
<strong>push</strong> 给 <strong>观察者</strong>, 当然 <strong>观察者</strong> 也可以实现 <strong>pull</strong> 来获取自己
感兴趣的变化.</p>
<p class="last">可以参见p67页的讨论.</p>
</div>
<p>下载请点击 <a href="../_downloads/observer.cpp"><strong class="xref">这里</strong></a></p>
<div class="highlight-c++"><table class="highlighttable"><tr><td class="linenos"><pre>  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134</pre></td><td class="code"><div class="highlight"><pre><span class="cp">#include&lt;iostream&gt;</span>
<span class="cp">#include&lt;vector&gt;</span>
<span class="cp">#include&lt;string&gt;</span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>

<span class="k">class</span> <span class="nc">Observer</span>
<span class="p">{</span>
    <span class="k">public</span><span class="o">:</span>
        <span class="k">virtual</span> <span class="kt">void</span> <span class="n">update</span><span class="p">(</span><span class="kt">float</span> <span class="n">temp</span><span class="p">,</span> <span class="kt">float</span> <span class="n">humidity</span><span class="p">,</span> <span class="kt">float</span> <span class="n">pressure</span><span class="p">){}</span>
<span class="p">};</span>

<span class="k">class</span> <span class="nc">Subject</span>
<span class="p">{</span>
    <span class="k">public</span><span class="o">:</span>
        <span class="k">virtual</span> <span class="kt">void</span> <span class="n">registerObserver</span><span class="p">(</span><span class="n">Observer</span> <span class="n">o</span><span class="p">){};</span>
        <span class="k">virtual</span> <span class="kt">void</span> <span class="n">removeObserver</span><span class="p">(</span><span class="n">Observer</span> <span class="n">o</span><span class="p">){};</span>
        <span class="k">virtual</span> <span class="kt">void</span> <span class="n">notifyObserver</span><span class="p">(){};</span>
<span class="p">};</span>

<span class="k">class</span> <span class="nc">DisplayElement</span>
<span class="p">{</span>
    <span class="k">public</span><span class="o">:</span>
        <span class="k">virtual</span> <span class="kt">void</span> <span class="n">display</span><span class="p">(){};</span>
<span class="p">};</span>

<span class="k">class</span> <span class="nc">WeatherData</span><span class="o">:</span><span class="k">public</span> <span class="n">Subject</span>
<span class="p">{</span>
    <span class="k">public</span><span class="o">:</span>
        <span class="n">vector</span><span class="o">&lt;</span><span class="n">Observer</span><span class="o">*&gt;</span> <span class="n">observers</span><span class="p">;</span>
        <span class="kt">float</span> <span class="n">temperature</span><span class="p">;</span>
        <span class="kt">float</span> <span class="n">humidity</span><span class="p">;</span>
        <span class="kt">float</span> <span class="n">pressure</span><span class="p">;</span>

        <span class="kt">void</span> <span class="n">registerObserver</span><span class="p">(</span><span class="n">Observer</span> <span class="o">*</span><span class="n">o</span><span class="p">)</span>
        <span class="p">{</span>
            <span class="n">observers</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">o</span><span class="p">);</span>
        <span class="p">}</span>
        <span class="kt">void</span> <span class="n">removeObserver</span><span class="p">(</span><span class="n">Observer</span> <span class="o">*</span><span class="n">o</span><span class="p">)</span>
        <span class="p">{</span>
            <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span> <span class="n">i</span><span class="o">&lt;</span><span class="n">observers</span><span class="p">.</span><span class="n">size</span><span class="p">();</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
                <span class="k">if</span> <span class="p">(</span><span class="n">observers</span><span class="p">.</span><span class="n">at</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="o">==</span> <span class="n">o</span><span class="p">)</span>
                <span class="p">{</span>
                    <span class="n">observers</span><span class="p">.</span><span class="n">erase</span><span class="p">(</span><span class="n">observers</span><span class="p">.</span><span class="n">begin</span><span class="p">()</span><span class="o">+</span><span class="n">i</span><span class="p">);</span>
                    <span class="k">break</span><span class="p">;</span>
                <span class="p">}</span>
        <span class="p">}</span>
        <span class="kt">void</span> <span class="n">notifyObserver</span><span class="p">()</span>
        <span class="p">{</span>
            <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span> <span class="n">i</span><span class="o">&lt;</span><span class="n">observers</span><span class="p">.</span><span class="n">size</span><span class="p">();</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
            <span class="p">{</span>
                <span class="n">observers</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-&gt;</span><span class="n">update</span><span class="p">(</span><span class="n">temperature</span><span class="p">,</span> <span class="n">humidity</span><span class="p">,</span> <span class="n">pressure</span><span class="p">);</span>  <span class="c">// 这是一种 push的方式</span>
            <span class="p">}</span>
        <span class="p">}</span>
        <span class="kt">void</span> <span class="n">measurementsChanged</span><span class="p">()</span>
        <span class="p">{</span>
            <span class="n">notifyObserver</span><span class="p">();</span>
        <span class="p">}</span>
        <span class="kt">void</span> <span class="n">setMeasurements</span><span class="p">(</span><span class="kt">float</span> <span class="n">temp</span><span class="p">,</span> <span class="kt">float</span> <span class="n">hum</span><span class="p">,</span> <span class="kt">float</span> <span class="n">pres</span><span class="p">)</span>
        <span class="p">{</span>
            <span class="n">temperature</span> <span class="o">=</span> <span class="n">temp</span><span class="p">;</span>
            <span class="n">humidity</span> <span class="o">=</span> <span class="n">hum</span><span class="p">;</span>
            <span class="n">pressure</span> <span class="o">=</span> <span class="n">pres</span><span class="p">;</span>
            <span class="n">measurementsChanged</span><span class="p">();</span>
        <span class="p">}</span>
        <span class="kt">float</span> <span class="n">getTemperature</span><span class="p">(){</span><span class="k">return</span> <span class="n">temperature</span><span class="p">;}</span>
        <span class="kt">float</span> <span class="n">getHumidity</span><span class="p">(){</span><span class="k">return</span> <span class="n">humidity</span><span class="p">;}</span>
        <span class="kt">float</span> <span class="n">getPressure</span><span class="p">(){</span><span class="k">return</span> <span class="n">pressure</span><span class="p">;}</span>
<span class="p">};</span>

<span class="k">class</span> <span class="nc">CurrentConditionDisplay</span><span class="o">:</span><span class="k">public</span> <span class="n">Observer</span><span class="p">,</span> <span class="k">public</span> <span class="n">DisplayElement</span>
<span class="p">{</span>
    <span class="k">private</span><span class="o">:</span>
        <span class="kt">float</span> <span class="n">temperature</span><span class="p">;</span>
        <span class="kt">float</span> <span class="n">humidity</span><span class="p">;</span>

    <span class="k">public</span><span class="o">:</span>
        <span class="kt">void</span> <span class="n">update</span><span class="p">(</span><span class="kt">float</span> <span class="n">temp</span><span class="p">,</span> <span class="kt">float</span> <span class="n">humidity</span><span class="p">,</span> <span class="kt">float</span> <span class="n">pressure</span><span class="p">)</span>
        <span class="p">{</span>
            <span class="k">this</span><span class="o">-&gt;</span><span class="n">temperature</span> <span class="o">=</span> <span class="n">temp</span><span class="p">;</span>
            <span class="k">this</span><span class="o">-&gt;</span><span class="n">humidity</span> <span class="o">=</span> <span class="n">humidity</span><span class="p">;</span>
            <span class="n">display</span><span class="p">();</span>
        <span class="p">}</span>
        <span class="kt">void</span> <span class="n">display</span><span class="p">()</span>
        <span class="p">{</span>
            <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="s">&quot;Current Conditions&quot;</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="p">;</span>
            <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="s">&quot;temperature:&quot;</span><span class="o">&lt;&lt;</span><span class="n">temperature</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="p">;</span>
            <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="s">&quot;humidity:&quot;</span><span class="o">&lt;&lt;</span><span class="n">humidity</span><span class="o">&lt;&lt;</span><span class="s">&quot;%&quot;</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="p">;</span>
            <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="p">;</span>
        <span class="p">}</span>
<span class="p">};</span>

<span class="k">class</span> <span class="nc">ForcastConditionDisplay</span><span class="o">:</span><span class="k">public</span> <span class="n">Observer</span><span class="p">,</span> <span class="k">public</span> <span class="n">DisplayElement</span>
<span class="p">{</span>
    <span class="k">private</span><span class="o">:</span>
        <span class="kt">float</span> <span class="n">temperature</span><span class="p">;</span>
        <span class="kt">float</span> <span class="n">humidity</span><span class="p">;</span>
        <span class="kt">float</span> <span class="n">pressure</span><span class="p">;</span>
        
    <span class="k">public</span><span class="o">:</span>
        <span class="kt">void</span> <span class="n">update</span><span class="p">(</span><span class="kt">float</span> <span class="n">temp</span><span class="p">,</span> <span class="kt">float</span> <span class="n">humidity</span><span class="p">,</span> <span class="kt">float</span> <span class="n">pressure</span><span class="p">)</span>
        <span class="p">{</span>
            <span class="k">this</span><span class="o">-&gt;</span><span class="n">temperature</span> <span class="o">=</span> <span class="n">temp</span><span class="p">;</span>
            <span class="k">this</span><span class="o">-&gt;</span><span class="n">humidity</span> <span class="o">=</span> <span class="n">humidity</span><span class="p">;</span>
            <span class="k">this</span><span class="o">-&gt;</span><span class="n">pressure</span> <span class="o">=</span> <span class="n">pressure</span><span class="p">;</span>
            <span class="n">display</span><span class="p">();</span>
        <span class="p">}</span>
        <span class="kt">void</span> <span class="n">display</span><span class="p">()</span>
        <span class="p">{</span>
            <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="s">&quot;Forcast&quot;</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="p">;</span>
            <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="s">&quot;temperature:&quot;</span><span class="o">&lt;&lt;</span><span class="n">temperature</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="p">;</span>
            <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="s">&quot;humidity:&quot;</span><span class="o">&lt;&lt;</span><span class="n">humidity</span><span class="o">&lt;&lt;</span><span class="s">&quot;%&quot;</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="p">;</span>
            <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="s">&quot;pressure:&quot;</span><span class="o">&lt;&lt;</span><span class="n">pressure</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="p">;</span>
            <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="p">;</span>
        <span class="p">}</span>
<span class="p">};</span>

<span class="kt">int</span> <span class="n">main</span><span class="p">()</span>
<span class="p">{</span>
    <span class="n">Subject</span> <span class="o">*</span><span class="n">s</span><span class="p">;</span>
    <span class="n">WeatherData</span> <span class="n">weather</span><span class="p">;</span>
    <span class="n">s</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">weather</span><span class="p">;</span>
    <span class="n">CurrentConditionDisplay</span> <span class="n">currentDisplay</span><span class="p">;</span>
    <span class="n">CurrentConditionDisplay</span> <span class="n">currentDisplay2</span><span class="p">;</span>
    <span class="n">ForcastConditionDisplay</span> <span class="n">forcastDisplay</span><span class="p">;</span>

    <span class="n">weather</span><span class="p">.</span><span class="n">registerObserver</span><span class="p">(</span><span class="o">&amp;</span><span class="n">currentDisplay</span><span class="p">);</span>
    <span class="n">weather</span><span class="p">.</span><span class="n">registerObserver</span><span class="p">(</span><span class="o">&amp;</span><span class="n">currentDisplay2</span><span class="p">);</span>
    <span class="n">weather</span><span class="p">.</span><span class="n">registerObserver</span><span class="p">(</span><span class="o">&amp;</span><span class="n">forcastDisplay</span><span class="p">);</span>

    <span class="n">weather</span><span class="p">.</span><span class="n">setMeasurements</span><span class="p">(</span><span class="mi">80</span><span class="p">,</span><span class="mi">62</span><span class="p">,</span><span class="mf">30.4</span><span class="p">);</span>
    <span class="n">weather</span><span class="p">.</span><span class="n">removeObserver</span><span class="p">(</span><span class="o">&amp;</span><span class="n">currentDisplay2</span><span class="p">);</span>
    <span class="n">weather</span><span class="p">.</span><span class="n">setMeasurements</span><span class="p">(</span><span class="mi">80</span><span class="p">,</span><span class="mi">62</span><span class="p">,</span><span class="mf">30.4</span><span class="p">);</span>
    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</td></tr></table></div>
<p>输出结果为:</p>
<div class="highlight-python"><pre>Current Conditions
temperature:80
humidity:62%


Current Conditions
temperature:80
humidity:62%


Forcast
temperature:80
humidity:62%
pressure:30.4

Current Conditions  //移除了一个观察者,则不再对其更新状态
temperature:80
humidity:62%


Forcast
temperature:80
humidity:62%
pressure:30.4</pre>
</div>
</div>
<div class="section" id="id5">
<h2>面对新的需要<a class="headerlink" href="#id5" title="永久链接至标题">¶</a></h2>
<p>如果这时要增加新的显示方法,可以这样应对:</p>
<ul class="simple">
<li>增加一个继承自 <strong>Observer</strong> 和 <strong>DisplayElement</strong> 的新类</li>
<li>在新类中实现 <strong>update</strong> 和 <strong>display</strong> 方法即可</li>
</ul>
</div>
<div class="section" id="id6">
<h2>更多注意<a class="headerlink" href="#id6" title="永久链接至标题">¶</a></h2>
<div class="section" id="id7">
<h3>设计准则<a class="headerlink" href="#id7" title="永久链接至标题">¶</a></h3>
<p><strong>Strive for loosely coupled designs between objects that interact.</strong></p>
</div>
</div>
<div class="section" id="id8">
<h2>参考更多<a class="headerlink" href="#id8" title="永久链接至标题">¶</a></h2>
<ol class="arabic simple">
<li><a class="reference external" href="http://blog.directededge.com/2009/05/21/c-and-c-are-not-the-same-language/">C and C++ are not the same language</a>
这篇文章使用C/C++/java分别实现了 <strong>observer</strong> 模式</li>
<li><a class="reference external" href="http://fsfoundry.org/codefreak/2009/05/24/observer-done-differently/">Observer Pattern, Done Differently</a>
使用 <strong>boost</strong> 库实现 <strong>observer</strong></li>
<li><a class="reference external" href="http://en.wikipedia.org/wiki/Observer_pattern">wikipedia Observer Pattern</a></li>
</ol>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../index.html">內容目录</a></h3>
            <ul>
<li><a class="reference external" href="">observer模式</a><ul>
<li><a class="reference external" href="#id1">observer模式定义</a></li>
<li><a class="reference external" href="#id3">问题描述</a></li>
<li><a class="reference external" href="#id4">具体的代码</a></li>
<li><a class="reference external" href="#id5">面对新的需要</a></li>
<li><a class="reference external" href="#id6">更多注意</a><ul>
<li><a class="reference external" href="#id7">设计准则</a></li>
</ul>
</li>
<li><a class="reference external" href="#id8">参考更多</a></li>
</ul>
</li>
</ul>

            <h4>上一个主题</h4>
            <p class="topless"><a href="strategy.html"
                                  title="上一章">strategy模式</a></p>
            <h4>下一个主题</h4>
            <p class="topless"><a href="decorator.html"
                                  title="下一章">decorator模式</a></p>
            <h3>本页</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/designpattern/observer.txt"
                     rel="nofollow">显示源代码</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>快速搜索</h3>
              <form class="search" action="../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="搜索" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              输入相关的模块，术语，类或者函数名称进行搜索
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="decorator.html" title="decorator模式"
             >下一页</a> |</li>
        <li class="right" >
          <a href="strategy.html" title="strategy模式"
             >上一页</a> |</li>
        <li><a href="../index.html">programming v0.1 documentation</a> &raquo;</li>
          <li><a href="index.html" >设计模式学习笔记</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; 版权所有 2009, zhutao.iscas@gmail.com.
      使用 <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.1.
    </div>
  </body>
</html>